<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="format-detection" content="telephone=no" />
    <title>租用</title>
    <link rel="stylesheet" href="../../css/reset.css">
    <style>
        body {
            width: 100%;
            background-color: #F8F8F8;
            font-size: 0.28rem;
            height: auto;
            -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
            font-family: PingFangSC-Regular, sans-serif;
            color: #333333;
        }

        .flex {
            display: flex;
            display: -ms-flex;
            display: -webkit-flex;
            display: -moz-flex;
        }

        input {
            border: none;
            outline: none;
        }

        .showDetail {
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
            background-color: #fff;
        }

        .showDetail li {
            display: flex;
            display: -webkit-flex;
            height: auto;
            padding: 0 0.24rem;
            box-sizing: border-box;
        }

        .showDetail li p {
            width: 100%;
            height: auto;
            display: flex;
            display: -webkit-flex;
            align-items: center;
            justify-content: space-between;
            /* border-bottom: 0.01rem solid #e2e2e2; */
            font-size: 0.28rem;
            padding: 0.1rem 0;
        }

        .showDetail .limitText {
            line-height: 0.68rem;
            height: 0.68rem
        }

        .showDetail li:last-child>p {
            border-bottom: 0;
        }

        .showDetail li p span:first-of-type {
            font-size: 0.28rem;
            color: #595959;
        }

        .showDetail li p span:last-of-type {
            font-weight: 500;
            font-size: 0.28rem;
            color: #262626;
        }

        .limitText {
            justify-content: flex-end;
            color: #ffa6a6;
            background-color: #f7f7f7;
            align-items: center;
        }

        #showButton {
            height: auto;
        }

        #showButton .rentNumber {
            display: flex;
            display: -webkit-flex;
            align-items: stretch;
        }

        #showButton .rentNumber span {
            display: inline-block;
            height: 0.6rem;
            width: 0.6rem;
            font-size: 0.4rem;
            line-height: 0.6rem;
            text-align: center;
            background-color: #f7f7f7;
            color: #878787;
        }

        #showButton .rentNumber input {
            display: inline-block;
            width: 1.45rem;
            text-align: center;
            background-color: #f7f7f7;
            color: #878787;
            margin: 0 0.1rem;
            font-size: 0.28rem;
            border-radius: 0;
        }

        .rightData {
            align-items: center;
            -webkit-align-items: center
        }

        .payMoney {
            font-size: 0.3rem;
            font-weight: bold;
            color: rgba(246, 115, 17, 1);
            margin-left: 0.14rem;
            display: flex;
            display: -webkit-flex;
            align-items: flex-end;
        }

        .dw {
            font-size: 0.28rem;
            color: #F67311;
            padding-left: 0.1rem;
            font-weight: bold;
        }

        .showDetail .hideBorder {
            height: 0.2rem;
            background: #f7f7f7;
            display: none
        }

        .choseTitle {
            padding: 0 0.24rem;
            background: #ffffff;
            border-top: 0.2rem solid #f8f8f8;
        }

        .choseTitle>span:first-child {
            font-size: 0.24rem;
            color: #b1b1b1;
        }

        .choseTitle>span:last-child {
            font-size: 0.22rem;
            color: #181818;
            float: right
        }

        .payWay_Box {
            padding: 0 0.24rem;
            background: #fff;
        }

        .payWay_Box {
            color: #181818;
        }

        .payLogo {
            width: 0.56rem;
            vertical-align: middle;
            margin-left: 0.1rem;
            margin-right: 0.22rem
        }

        .payWayTxt {
            font-size: 0.27rem;
        }

        .this_leastM {
            font-size: 0.24rem;
            padding-left: 0.1rem
        }

        input[type=radio] {
            border: 0;
            width: 0.44rem;
            height: 0.44rem;
            position: absolute;
            z-index: 2;
            right: 0;
            top: 50%;
            margin: 0;
            margin-top: -0.22rem;
            opacity: 0
        }

        .radioStyle {
            width: 0.2rem;
            height: 0.2rem;
        }

        .payWay_Box label {
            line-height: 1.06rem;
            position: relative;
            border-bottom: 0.01rem solid#eaeaea;
            height: 100%;
            display: block;
            display: flex;
            display: -webkit-flex;
            align-items: center;
            justify-content: flex-start;
            box-sizing: border-box;
        }

        .payWay_Box label:last-child {
            border-bottom: 0;
        }

        .radioStyle {
            /* float: right; */
            width: 0.44rem;
            height: 0.44rem;
            display: inline-block;
            background: #fff;
            border-radius: 50%;
            box-sizing: border-box;
            position: absolute;
            z-index: 1;
            right: 0;
            margin-top: -0.22rem;
            top: 50%;
            border: 0.01rem solid#656565;
        }

        input[type=radio]:checked+.radioStyle {
            border: 0;
            background: url("../../image/checknew.png") center center no-repeat;
            background-size: 100% 100%;
        }

        #agreementinput {
            opacity: 0;
            position: absolute;
            z-index: 2;
            width: 100%;
            height: 100%;
            margin: 0;
            border: 0;
            left: 0;
            top: 0
        }

        .rementLabel {
            display: inline-block;
            box-sizing: border-box;
            position: relative;
            line-height: 0.5rem;
        }

        .rementLabel .agreement_style {
            width: 0.28rem;
            height: 0.28rem;
            position: absolute;
            z-index: 1;
            margin: 0;
            border: 0.02rem solid#999999;
            border-radius: 0.04rem;
            left: 0;
            top: 0;
        }

        .rementLabel>span:last-child {
            font-size: 0.27rem;
            vertical-align: middle
        }

        .rementLink {
            color: #ffd203;
            line-height: 0.5rem
        }

        .rentBtn {
            display: inline-block;
            width: calc(100% - 0.48rem);
            background: #ffd203;
            color: #181818;
            height: 0.88rem;
            border-radius: 0.04rem;
            line-height: 0.88rem;
            text-decoration: unset;
            font-size: 0.28rem
        }

        .rementLabel .agreement_style_checked {
            width: 0.28rem;
            height: 0.28rem;
            position: absolute;
            z-index: 1;
            margin: 0;
            border-radius: 0.04rem;
            left: 0;
            top: 0;
        }

        .rementLabel .agreement_style_checked:after {
            content: '';
            width: 0.34rem;
            height: 0.34rem;
            position: absolute;
            top: -0.04rem;
            left: -0.04rem;
            background: url("../../image/checkeasd.png") no-repeat center;
            background-size: 100% 100%;
            border: 2px solid #ffffff;
            z-index: 2;
        }

        .notAgree {
            background: #e6e6e6;
        }

        .fenqigou {
            width: 100%;
            height: 1.1rem;
            display: flex;
            display: -webkit-flex;
            align-items: center;
            justify-content: space-between;
            border-top: 0.2rem solid #f8f8f8;
            padding: 0 0.3rem;
            box-sizing: border-box;
            overflow: hidden;
            position: relative;
            background-color: #fff;
        }

        #fenqiBuy {
            width: 100%;
            height: 100%;
            display: flex;
            display: -webkit-flex;
            align-items: center;
            font-size: 0.28rem;
            font-family: PingFang SC;
            font-weight: 400;
            color: rgba(38, 38, 38, 1);
        }

        #checkInput+label::before {
            content: " ";
            display: inline-block;
            width: 0.44rem;
            height: 0.44rem;
            box-sizing: border-box;
            background: url("../../image/iconxuangousuanlibaox.png") center center no-repeat;
            background-size: 100% 100%;
            padding: .1rem;
            border-radius: 0.44rem;
            margin-right: 0.1rem;
        }

        #checkInput:checked+label::before {
            display: inline-block;
            width: 0.44rem;
            height: 0.44rem;
            box-sizing: border-box;
            background: url("../../image/iconxuangousuanlibao.png") center center no-repeat;
            background-size: 100% 100%;
            padding: .1rem;
            border: none;
            border-radius: 0.44rem;
            margin-right: 0.1rem;
        }

        #checkInput {
            position: absolute;
            clip: rect(0, 0, 0, 0);
        }

        .floatMoney {
            display: block;
            position: absolute;
            right: 0.3rem;
            top: 35%;
            font-size: 0.22rem;
            font-family: PingFang SC;
            font-weight: 400;
            color: rgba(153, 153, 153, 1);
        }

        .needPayNum {
            font-weight: bold;
            color: rgba(236, 42, 9, 1);
        }

        .fenQiDetail {
            width: 100%;
            padding: 0 0.3rem;
            box-sizing: border-box;
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
            align-items: flex-start;
            justify-content: flex-start;
        }

        .fenQiDetail>p {
            width: 100%;
            height: auto;
            display: flex;
            display: -webkit-flex;
            align-items: center;
            justify-content: space-between;
            font-size: 0.24rem;
            font-family: PingFang SC;
            font-weight: 400;
            color: rgba(89, 89, 89, 1);
            margin-bottom: 0.24rem;
        }

        .fenQiDetail>p:first-of-type {
            border-top: 1px solid rgba(238, 238, 238, 1);
            padding-top: 0.3rem;
        }

        .fenQiDetail>p span:last-of-type {
            font-weight: bold;
            color: rgba(38, 38, 38, 1);
        }

        .moneyPayDetail {
            width: 100%;
            display: flex;
            display: -webkit-flex;
            flex-wrap: wrap;
            align-items: center;
            justify-content: space-between;
        }

        .moneyPayDetail li {
            width: 3.4rem;
            height: 1.2rem;
            background: rgba(248, 248, 248, 1);
            border-radius: 0.04rem;
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
            justify-content: center;
            align-items: flex-start;
            padding-left: 0.2rem;
            box-sizing: border-box;
            margin-bottom: 0.18rem;
            font-size: 0.24rem;
            font-family: PingFang SC;
            font-weight: 500;
            color: rgba(38, 38, 38, 1);
            border: 1px solid rgba(248, 248, 248, 1);
        }

        .moneyPayDetail li p:nth-of-type(2) {
            margin-top: 0.08rem;
            font-size: 0.2rem;
            font-family: PingFang SC;
            font-weight: 500;
            color: rgba(89, 89, 89, 1);
            display: flex;
            display: -webkit-flex;
            align-items: center;
            justify-content: flex-start;
        }

        .showDischareNum {
            font-size: 0.14rem;
            font-weight: 500;
            text-decoration: line-through;
            color: rgba(153, 153, 153, 1);
        }

        .moneyPayDetail .chooseli {
            background: rgba(255, 251, 239, 1);
            border: 1px solid rgba(255, 210, 3, 1);
        }

        .moneyPayDetail .nochooseli {
            background: rgba(248, 248, 248, 1);
            border: 1px solid rgba(248, 248, 248, 1);
        }

        .showContract {
            width: 100%;
            padding: 0.12rem 0.61rem 0.12rem 0.3rem;
            box-sizing: border-box;
            text-indent: -.2rem;
            margin-left: 0.4rem;
        }

        .checkButton {
            width: 100%;
            height: auto;
            display: flex;
            display: -webkit-flex;
            flex-direction: column;
            align-items: flex-start;
            justify-content: flex-end;
            position: fixed;
            bottom: 0;
            left: 0;
            background-color: #fff;
        }

        .showMoneyBox {
            width: 100%;
            height: 1rem;
            display: flex;
            display: -webkit-flex;
            align-items: stretch;
            justify-content: flex-start;
            border-top: 1px solid rgba(229, 229, 229, 1);
        }

        .showMoneyBox p {
            flex: 1;
            display: flex;
            display: -webkit-flex;
            align-items: center;
            justify-content: flex-start;
            font-size: 0.24rem;
            color: #898989;
            padding-left: 0.3rem;
            box-sizing: border-box;
        }

        .showMoneyBox button {
            outline: none;
            border: none;
            width: 2rem;
            height: 1rem;
            display: flex;
            display: -webkit-flex;
            align-items: center;
            justify-content: center;
            font-size: 0.3rem;
            font-weight: 500;
            color: rgba(38, 38, 38, 1);
            background-color: #ffd203;
        }
    </style>
</head>

<body>
    <div>
        <ul class="showDetail">
            <li>
                <p style="margin-top: 0.15rem;">
                    <span>
                        用户名
                    </span>
                    <span class="uesePhone"></span>
                </p>
            </li>
            <li>
                <p style="margin-bottom: 0.15rem;">
                    <span>名称</span>
                    <span class="machineName"></span>
                </p>
            </li>
            <li id="showButton" style="border-top: 0.2rem solid #f7f7f7;">
                <p style="margin-top:0.15rem;">
                    <span>
                        购买份额
                    </span>
                    <span class="rentNumber rightData flex">
                        <span class="addbButton">－</span>
                        <input type="text" id="inputNumber" value="1">
                        <span class="disButton">＋</span>
                    </span>
                </p>
            </li>
            <li class="showAllPower" style="margin-bottom: 0.1rem;">
                <p>
                    <span>
                        BTC算力
                    </span>
                    <span class="getAllPower rightData flex">
                        <span class="powerNum">
                            <span></span>
                        </span>
                        <img src="../../image/rightjt.png" alt=""
                            style="width:0.16rem;height:0.29rem;margin-left: 0.24rem;">
                    </span>
                </p>
            </li>
            <li class="showBhpPowerNum" style="display: none;margin-bottom: 0.1rem;">
                <p>
                    <span>BHP参配算力</span>
                    <span class="bhpDisPower">
                        0.00 T
                    </span>
                </p>
            </li>
            <!-- <li>
                <p>
                    <span>总计需付金额</span>
                    <span class="getAllPower">
                        <span class="payMoney">9000</span><span class="dw">USDT</span>
                    </span>
                </p>
            </li> -->
        </ul>
        <div class="fenqigou hideFenQi" style="display: none;">
            <input type="checkbox" name="checkInput" id="checkInput">
            <label for="checkInput" id="fenqiBuy">
                <span>
                    分期购
                </span>
                <sapn class="floatMoney">
                    可分期总金额<span class="fenqiPre">--</span>%,需首付<span class="needPayNum">--CNY</span>
                </sapn>
            </label>
        </div>
        <div class="fenQiDetail" style="display: none;">
            <p>
                <span>
                    分期本金
                </span>
                <span class="totalrepayment">

                </span>
            </p>
            <p>
                <span>
                    服务费
                </span>
                <span class="fenQiSevrce">
                    -- CNY
                </span>
            </p>
            <ul class="moneyPayDetail">
                <!-- <li class="chooseli">
                    <p>
                        -- CNY
                    </p>
                    <p>
                        <span>
                            含手续费 -- CNY/期
                        </span>
                    </p>
                    <p class="showDischareNum">
                        -- CNY/期
                    </p>
                </li>
                <li>
                    <p>
                        -- CNY
                    </p>
                    <p>
                        <span>
                            含手续费 -- CNY/期
                        </span>
                    </p>
                    <p class="showDischareNum">
                        -- CNY/期
                    </p>
                </li>
                <li>
                    <p>
                        -- CNY
                    </p>
                    <p>
                        <span>
                            含手续费 -- CNY/期
                        </span>
                    </p>
                    <p class="showDischareNum">
                        -- CNY/期
                    </p>
                </li>
                <li>
                    <p>
                        -- CNY
                    </p>
                    <p>
                        <span>
                            含手续费 -- CNY/期
                        </span>
                    </p>
                    <p class="showDischareNum">
                        -- CNY/期
                    </p>
                </li> -->
            </ul>
        </div>
        <div class="choseTitle">
            <p
                style="width: 100%;padding: 0.24rem 0;box-sizing: border-box;border-bottom: 1px solid #EAEAEA;font-size: 0.24rem;color: #999999;display: flex;display: -webkit-flex;align-items: center;justify-content: space-between;">
                <span>选择支付方式</span>
                <span>1 <span class="chosePayMethod"></span><span class="exchange_rate"></span> CNY</span>
            </p>
        </div>
        <div class="payWay_Box">
            <label for="wallet" id="walletPay">
                <img src="../../image/cnyiconimg.png" alt="" class="payLogo">
                <span class="payWayTxt">CNY</span>
                <span class="this_leastM">(可用: <span></span>)</span>
                <input type="radio" name="payWay" value="CNY" id="wallet" data-paymethod="RRM_CASH">
                <span class="radioStyle"></span>
            </label>
            <label for="usdt" id="usdtPay">
                <img src="../../image/usdt.png" alt="" class="payLogo">
                <span class="payWayTxt">USDT支付</span>
                <span class="this_leastM">(余额: <span></span>)</span>
                <input type="radio" name="payWay" id="usdt" value="USDT" data-paymethod="RRM_USDT">
                <span class="radioStyle"></span>
            </label>
        </div>
        <div class="checkButton">
            <p class="showContract">
                <label class="rementLabel">
                    <span
                        style="position: relative;width: 0.3rem;height: 0.3rem;display: inline-block;vertical-align: middle;margin-right: 0.05rem">
                        <input type="checkbox" id="agreementinput" name="agreement">
                        <span class="ag_checkedstyle agreement_style"></span>
                    </span>
                    <span style="vertical-align: middle;font-size: 0.27rem;">我同意</span>
                </label>
            </p>
            <div class="showMoneyBox">
                <p>
                    <span style="display: flex;display: -webkit-flex;align-items: flex-end;">
                        总计金额<span class="payMoney"></span><span class="dw">USDT</span>
                    </span>
                </p>
                <button id="checkButton">
                    立即支付
                </button>
            </div>
        </div>
    </div>
    <script src="../../script/autosize.js"></script>
    <script src="../../script/jquery_three_two_one.js"></script>
    <script src="../../script/fastclick.js"></script>
    <script src="../../script/dotmin.js"></script>
    <script src="../../script/app.js"></script>
    <script>
        apiready = function () {
            var validateTokenNew = "";
            var app = new APP();
            var account = app.getAccount();
            $(".checkButton").css("bottom", app.safetyFooterArea);
            var machineDeatail = api.pageParam.machineDeatail;//矿机详情
            var userMoney = api.pageParam.userAset;//用户资产
            $(".uesePhone").text(account.telphone);
            $(".machineName").text(machineDeatail.name); //矿机名称
            var not_return = machineDeatail.type;//是否是高风险合约包 10是
            var pay_way = 'bcny'; //默认支付方式；限页面样式使用
            var payMethod = 'RRM_USDT'; //ajax传参使用的支付方式
            var minRent = Number(machineDeatail.minLimitNum); //最低租用数量
            var rent_num = machineDeatail.minLimitNum; //租用矿机数量
            var num_limit = machineDeatail.maxLimitNum > 0 ? machineDeatail.maxLimitNum : machineDeatail.batchLimitNum; //最大租用数量
            var agreementinput = false; //是否同意协议
            var typeMachine = machineDeatail.currency_code; //矿机类型
            var machineId = machineDeatail.machine_id; //矿机id
            var num_left = app.accMul(machineDeatail.base_power, machineDeatail.productNum) //库存
            var goods_deposit = api.pageParam.payCnyNum; //单个押金
            var is_bhp_pos = machineDeatail.is_bhp_pos; //判断是不是双挖
            var machineTypeNew = machineDeatail.machineTypeNew;
            var machinePowerData = machineDeatail; //机器详情
            var rmb_left = api.pageParam.userAset.CNY; //钱包余额
            var usdt_left = api.pageParam.userAset.USDT; //usdt余额
            var exchange_rate = machineDeatail.exchange_rate; //usdt兑换汇率
            var usdt_unit_pay = api.pageParam.payUsdtNum; //矿机单份usdt支付金额
            var publicExchange = 1; //公共调用单份支付金额！！！
            var is_usdt_pay = api.pageParam.payUsdtNum > 0 ? 1 : 0; //是否支持usdt支付
            var unit_payWay = 'CNY'; //支付方式单位
            var rent_money = 0; //支付金额( usdt会经过换算 )
            var allPower; //总算力
            var contractText = machineDeatail.contract;
            var bhpPower = machineDeatail.bhp_power;//每份BHP参配算力
            var isAllPayment = machineDeatail.is_all_payment;//是否支持全款 0否 1是
            var isInstallment = machineDeatail.is_installment;//是否支持分期 0否 1是
            var downPaymentRate = machineDeatail.down_payment_rate || 0;//首付分期金额
            $(".fenqiPre").text(app.accMul(app.numSub(1, downPaymentRate), 100));
            for (var i = 0; i < contractText.length; i++) {
                var thisText = contractText[i].name + "&" + contractText[i].code;
                var temple = '<span class="rementLink" style="font-size: 0.24rem;" data-value=' + thisText + '>《' + contractText[i].name + '》</span>'
                $(".showContract").append(temple);
            };
            var arrivePower = []; //达标算力区间
            var pe_powerData = api.pageParam.pe_power;//达标算力
            for (var i in pe_powerData) {
                var element = {
                    basePower: i,
                    section: pe_powerData[i]
                };
                arrivePower.push(element);
            }
            var dataPower = {
                basePower: "",
                pePower: "",
                futuresPower: "",
                standPower: "",
                floatPower: "",
                calculatePower: ""
            };
            //公用弹出充值弹窗
            var firstInAdd = false;
            var limitRentUnit = "T";
            if (typeMachine != "BTC") {
                limitRentUnit = "M";
            }
            typeMachine = 'BTC';
            var userIdName; //用户实名状态
            var is_captcha = machineDeatail.is_tongdun_on;
            $("#walletPay .this_leastM>span").text(app.sliceNum(rmb_left, 2));
            $("#usdtPay .this_leastM>span").text(app.sliceNum(usdt_left, 4));
            //清空分期购数据
            function clearNum(params) {
                $(".totalrepayment,.fenQiSevrce").text("");
                $(".moneyPayDetail").empty();
                $(".needPayNum").text("--CNY");
                $(".hideFenQi,.fenQiDetail").hide();
                $("#checkInput").prop("checked", false);
                installmentNum = 0, sku_id = "", once_repayment = 0, installment_amount = 0, once_fee = 0;
            }
            function pageBind() {
                //选择支付方式
                $("input[name=payWay]").unbind('change').bind('change', function () {
                    unit_payWay = $(this).val();
                    pay_way = $(this).attr('id');
                    payMethod = $(this).data('paymethod');
                    console.log("")
                    if (unit_payWay == 'USDT') {
                        publicExchange = exchange_rate;
                    } else if (unit_payWay == "BCNY") {
                        publicExchange = 1;
                    } else {
                        publicExchange = 1;
                        if (isInstallment == 1) {
                            $(".hideFenQi").show();
                        }
                    }
                    exchange();
                    getAllRentMoney();
                    showAddWindow();
                    //支持分期&&支付选择钱包&&选择了分期购
                    if (isInstallment == 1 && pay_way == "wallet" && $("#checkInput").is(":checked") == true) {
                        getIsOpenFenqi(rent_money, machineId);
                    }
                });
                //输入数量变化
                $("#inputNumber").unbind("input porpertychange change keyup").bind("input porpertychange change keyup", function () {
                    var thizval = $(this).val();
                    if (thizval > num_limit) {
                        thizval = num_limit;
                        app.toast("已达到单次最大下单限额");
                    }
                    rent_num = thizval;
                    $(this).val(rent_num);
                    getFloatPower(machinePowerData, rent_num, typeMachine, arrivePower);
                    checkeckLabel(false);
                    getAllRentMoney();
                });
                $("#inputNumber").unbind('blur').bind('blur', function () {
                    var thizval = $(this).val();
                    if (thizval > num_limit) {
                        thizval = num_limit;
                    }
                    if (thizval < minRent) {
                        thizval = minRent;
                    }
                    rent_num = thizval;
                    $(this).val(rent_num);
                    getFloatPower(machinePowerData, rent_num, typeMachine, arrivePower);
                    checkeckLabel(false);
                    getAllRentMoney();
                });
                $(".addbButton").unbind('tap click').bind('tap click', function () {
                    if (rent_num > minRent) {
                        rent_num--;
                    }
                    $("#inputNumber").val(rent_num);
                    getFloatPower(machinePowerData, rent_num, typeMachine, arrivePower);
                    checkeckLabel();
                    getAllRentMoney();
                });
                $(".disButton").unbind('tap click').bind('tap click', function () {
                    if (rent_num < num_limit) {
                        rent_num++;
                    } else {
                        app.toast("已达到单次最大下单限额");
                    }
                    $("#inputNumber").val(rent_num);
                    getFloatPower(machinePowerData, rent_num, typeMachine, arrivePower);
                    checkeckLabel();
                    getAllRentMoney();
                });
            }
            checkeckLabel(true);
            pageBind();
            //防抖函数 
            //  3    @param fn {Function}   实际要执行的函数
            //  4   @param delay {Number}  延迟时间，也就是阈值，单位是毫秒（ms）
            //  6    @return {Function}     返回一个“去弹跳”了的函数
            function debounce(fn, delay) {
                var timer;
                return function () {
                    var context = this;
                    var args = arguments;
                    clearTimeout(timer);
                    timer = setTimeout(function () {
                        fn.apply(context, args)
                    }, delay)
                }
            };
            //请求分期购详情 
            function fenQiList(moneyNum, machineId) {
                $(".needPayNum").text(app.accMul(moneyNum, downPaymentRate) + "CNY");
                moneyNum = app.accMul(moneyNum, app.numSub(1, downPaymentRate));
                app.ajaxPro({
                    url: "hilink/trial",
                    values: {
                        token: account.token,
                        amount: moneyNum,
                        machine_id: machineId
                    },
                    openFlower: true
                }, function (ret) {
                    if (ret.code == 200) {
                        $(".fenQiDetail").show();
                        var dataList = ret.data.lists;
                        dataList.map(function (item) {
                            item.totalSevrce = app.accMul(item.once_fee, item.period_number);
                            item.total_repaymentnew = app.numSub(item.total_repayment, item.totalSevrce);
                        })
                        var temp = doT.template($("#fenQiContant").text());
                        $(".moneyPayDetail").html(temp(dataList)).find("li:first-of-type").click();
                    } else {
                        app.toast(ret.message);
                    }
                })
            }
            //请求用户是否首次阅读协议 readArgment= true 表示阅读过
            function getIsOpenFenqi(moneyNum, machineId) {
                var readArgment = app.parse(app.getSyncStorage("readArgment"));
                if (readArgment && readArgment == true) {
                    app.trigger("argeeArgeement");
                    return false
                } else {
                    app.setStorage("readArgment", "false");
                }
                app.ajaxPro({
                    url: "hilink/get-note",
                    values: {
                        token: account.token
                    },
                    openFlower: true
                }, function (ret) {
                    if (ret.code == 200) {
                        var param = {
                            dtype: "dialog87",
                            data: {
                                text: ret.data.contract.content,
                                event: "argeeArgeement"
                            }
                        };
                        app.dialog(param);
                    } else {
                        app.toast(ret.message);
                    }
                })
            }
            //监听取消阅读
            app.listen("cancleArdment", function (params) {
                $("#checkInput").prop("checked", false);
            })
            //请求用户是否实名 
            function userIsreal(params) {
                app.ajaxPro({
                    url: "member/is-real-apply",
                    values: {
                        token: account.token
                    },
                    openFlower: true
                }, function (ret) {
                    if (ret.code == 200) {
                        if (ret.data.status == 1) {//已经实名
                            var param = {
                                dtype: "dialog75",
                                data: {
                                    token: account.token
                                }
                            };
                            app.dialog(param);
                        } else {
                            app.toast("你尚未进行实名认证,请前往安全设置实名");
                        }
                    } else if (ret.code == 602) {
                        app.toast("亲,你的信息正在审核中……");
                    } else if (ret.code == 609 || ret.code == 614) {
                        app.toast("你尚未进行实名认证,请前往安全设置实名");
                    } else if (ret.code == 609) {
                        app.toast("你尚未进行实名认证,请前往安全设置实名");
                    } else {
                        app.toast("失败：" + ret.message);
                    }
                })
            }
            app.listen("argeeArgeement", function () {
                app.setStorage("readArgment", "true");
                var fenQiBuy = app.fenQiBuy();//查看储存的用户是否打开了分期购
                if (fenQiBuy == "true") {
                    $(".moneyPayDetail").empty();
                    fenQiList(rent_money, machineId);
                    return
                }
                app.ajaxPro({
                    url: "hilink/get-state",
                    values: {
                        token: account.token
                    },
                    openFlower: true
                }, function (ret) {
                    if (ret.code == 200) {
                        if (ret.data == 1) {
                            app.fenQiBuy("true");
                            $(".moneyPayDetail").empty();
                            fenQiList(rent_money, machineId);
                        } else {
                            app.fenQiBuy("false");
                            $("#checkInput").prop("checked", false);
                            userIsreal();
                        }
                    } else {
                        app.toast(ret.message);
                    }
                })
            })
            app.listen("goFenQi", function (ret) {
                app.ajaxPro({
                    url: "hilink/home",
                    values: {
                        token: account.token
                    },
                    openFlower: true
                }, function (ret) {
                    var recodeList = ret.data;
                    app.openWin({
                        name: "suanlijinrong",
                        url: recodeList,
                        slidBackEnabled: false
                    })
                })
            })
            $(".rentNumber span").on("click", debounce(function () {
                //支持分期&&支付选择钱包&&选择了分期购
                if (isInstallment == 1 && pay_way == "wallet" && $("#checkInput").is(":checked") == true) {
                    getIsOpenFenqi(rent_money, machineId);
                }
            }, 1000));
            $("#checkInput").on("change", function () {
                if (isInstallment == 1 && pay_way == "wallet" && $(this).is(":checked") == true) {
                    getIsOpenFenqi(rent_money, machineId);
                }
            });
            $("#inputNumber").on("input porpertychange", debounce(function (e) {
                if (isInstallment == 1 && pay_way == "wallet" && $("#checkInput").is(":checked") == true) {
                    getIsOpenFenqi(rent_money, machineId);
                }
            }, 2000));
            var installmentNum = 0;//分期期数
            var sku_id = "";//贷款ID
            var once_repayment = 0;//每次还款额度
            var installment_amount = 0;//分期手续费
            var once_fee = 0;//每次分期手续费
            //分期选择
            $(".moneyPayDetail").on("click", "li", function () {
                var totalMoney = $(this).attr("data-benjing");//分期总额
                installment_amount = $(this).attr("data-sevrieCharge");//分期总手续费
                installmentNum = $(this).attr("data-mouthNum");
                sku_id = $(this).attr("data-skuId");
                once_repayment = $(this).attr("data-onceRepayment");
                once_fee = $(this).attr("data-onceFee");
                $(this).removeClass("nochooseli").addClass("chooseli").siblings().addClass("nochooseli").removeClass("chooseli");
                $(".totalrepayment").text(totalMoney + " CNY");
                $(".fenQiSevrce").text(installment_amount + " CNY");
            });
            //计算汇率方法
            function exchange() {
                $(".chosePayMethod").text(unit_payWay);
                if (unit_payWay == 'USDT') {
                    console.log('usdt汇率' + exchange_rate);
                    $('.exchange_rate').text(" ≈ " + exchange_rate);
                } else if (unit_payWay == "BCNY") {
                    $(".chosePayMethod").text("OTC余额");
                    $('.exchange_rate').text(" = " + 1);
                } else {
                    $(".exchange_rate").text(" = " + 1);
                }
            }
            function checkeckLabel(needChecked) { //为true的话首次进入默认选择最后一个label的支付方式。。。为false的话是input输入框变化来选择label方式
                if (exchange_rate == 0) {
                    setTimeout(function () {
                        checkeckLabel(true);
                    }, 300);
                    return;
                }
                if (is_usdt_pay == 0) {
                    $("#usdtPay").remove();
                }
                if (needChecked) {
                    var firstPayBcnyMoney = minRent * 3000; //首次进入的需支付的BCNY金额
                    var firstPayUsdtMoney = usdt_unit_pay;
                    var enougnUsdt = Number(usdt_left) >= Number(firstPayUsdtMoney) ? true : false;
                    if (is_usdt_pay == 1 && enougnUsdt) {
                        setTimeout(function () {
                            $("#usdtPay input").click();
                        }, 300)
                    } else {
                        setTimeout(function () {
                            $("#walletPay input").click();
                        }, 300)
                    }
                }
            }
            //计算算力
            function getFloatPower(machinePowerData, retNum, typeMachine, arrivePower) {
                var baseData = app.accMul(Number(machinePowerData.base_power), retNum);
                var getCaculterPower = 0;
                if (typeMachine == "BTC" && machinePowerData.is_pe_power == 1) {
                    for (var i = 0; i < arrivePower.length; i++) {
                        var sectionForm = Number(arrivePower[i].basePower);
                        var sectionTo = 0;
                        var a = i + 1;
                        if (a < arrivePower.length) {
                            var sectionTo = Number(arrivePower[a].basePower);
                        }
                        if (Number(baseData) >= sectionForm && Number(baseData) < sectionTo) {
                            getCaculterPower = arrivePower[i].section;
                        }
                        var arrleng = arrivePower.length - 1;
                        if (Number(baseData) >= Number(arrivePower[arrleng].basePower)) {
                            getCaculterPower = arrivePower[arrleng].section
                        }
                    }
                };
                dataPower = {
                    basePower: baseData,
                    pePower: app.accMul(getCaculterPower, baseData),
                    futuresPower: app.accMul(Number(machinePowerData.futures_power), retNum),
                    standPower: app.accMoreMul(machinePowerData.regular_power, retNum, machinePowerData.base_power),
                    floatPower: app.accMul(Number(machinePowerData.float_power), retNum),
                    calculatePower: machinePowerData.td_power ? app.accMul(Number(machinePowerData.td_power), retNum) : 0
                }
                allPower = app.moreAccAdd(dataPower.basePower, dataPower.pePower, dataPower.futuresPower, dataPower.standPower, dataPower.floatPower, dataPower.calculatePower);
                $(".powerNum>span").text(allPower + limitRentUnit);
                if (is_bhp_pos == 1) {
                    $(".showBhpPowerNum").show();
                    var bhpPowerTotal = app.accMul(bhpPower, retNum);
                    $(".bhpDisPower").text(bhpPowerTotal + limitRentUnit);
                }
            }
            getFloatPower(machinePowerData, rent_num, typeMachine, arrivePower);
            $("#inputNumber").val(minRent);
            function getAllRentMoney() {
                if (unit_payWay == 'USDT') {
                    publicExchange = usdt_unit_pay;
                    rent_money = app.accMul(rent_num, publicExchange);
                } else {
                    rent_money = app.accMul(goods_deposit, rent_num)
                }
                $(".payMoney").text(rent_money);
                if (unit_payWay == "BCNY") {
                    $(".dw").text("OTC余额");
                } else {
                    $(".dw").text(unit_payWay);
                }
                if (isInstallment == 1) {
                    $(".needPayNum").text(app.accMul(rent_money, downPaymentRate) + "CNY");
                }
            }
            getAllRentMoney();
            function showAddWindow() {
                if (firstInAdd == false) {
                    firstInAdd = true;
                    return false;
                }
                var result = true;
                if (pay_way == 'wallet') {
                    if ((rmb_left < rent_money && isInstallment == 0) || (rmb_left < app.accMul(rent_money, downPaymentRate) && isInstallment == 1 && $("#checkInput").is(":checked") == true) || (rmb_left < rent_money && isInstallment == 1 && $("#checkInput").is(":checked") == false)) {
                        result = false;
                        var param = {
                            dtype: "dialog1",
                            data: {
                                title: "提示",
                                text: "CNY余额不足，请确认是否前去充值？",
                                btns: [{
                                    name: "取消",
                                    event: ""
                                },
                                {
                                    name: "确定",
                                    event: "charge"
                                }
                                ]
                            }
                        };
                        app.dialog(param);
                        return
                    }
                }
                if (pay_way == 'usdt') {
                    app.log('rent_money', rent_money);
                    app.log('usdt_left', usdt_left);
                    if (isInstallment == 1) {
                        clearNum();
                    }
                    if (Number(usdt_left) < rent_money) {
                        result = false;
                        var param = {
                            dtype: "dialog1",
                            data: {
                                title: "提示",
                                text: "USDT余额不足，请确认是否前去充值？",
                                btns: [{
                                    name: "取消",
                                    event: ""
                                },
                                {
                                    name: "确定",
                                    event: "charge"
                                }
                                ]
                            }
                        };
                        app.dialog(param);
                    }
                }
                return result;
            }
            var arrListen = ["charge", "chargeOTC"]
            app.listen(arrListen, function () {
                app.closeF("dialog");
                app.rechangChecked();
            });
            //租用ajax
            function rentMachine() {
                app.ajaxPro({
                    url: "order/rent",
                    values: {
                        token: account.token,
                        machine_id: machineId,//矿机id
                        num: rent_num,//购买数量
                        pay_channel: payMethod,//支付渠道
                        blackBox: is_captcha == 1 ? _fmOpt.getinfo() : "",
                        yzm_token: validateTokenNew,
                        is_installment: $("#checkInput").is(":checked") == true ? 1 : 0,//是否分期 0不是 1是
                        installmentNum: installmentNum,//分期期数
                        sku_code: sku_id,//贷款ID
                        once_repayment: once_repayment,//每次还款额度
                        installment_amount: installment_amount,//分期手续费
                        once_fee: once_fee,//每次分期手续费
                    },
                    openFlower: true
                }, function (ret) {
                    if (isInstallment == 1 && $("#checkInput").is(":checked") == true) {
                        if (ret.code == 200) {
                            setTimeout(function () {
                                app.openWin({
                                    name: "suanlijinrong",
                                    url: ret.data,
                                    slidBackEnabled: false
                                });
                            }, 1000)
                        } else {
                            var param = {
                                dtype: "dialog47",
                                data: {
                                    title: '提示',
                                    text: ret.message

                                }
                            };
                            app.dialog(param);
                        }
                    } else {
                        if (ret.code == 200) {
                            app.trigger("rent_successnews");
                            app.toast("下单成功");
                        } else {
                            app.trigger("rent_successnews");
                            app.toast(ret.message);
                        }
                        setTimeout(function (params) {
                            app.trigger("rent_success");
                            app.closeW();
                        }, 1000)
                    }
                })
            }
            app.listen("YESIKNOW", function () {
                var cointypecontract = {
                    page: "common/headerwin",
                    name: "littlemoneyrecharge_headerwin",
                    param: {
                        subpage: "extrapage/littlemoneyrecharge",
                        name: "littlemoneyrecharge",
                        title: "充值",
                        allowEdit: true
                    }
                };
                var recoinNumber = JSON.stringify(cointypecontract);
                app.goPushPage(recoinNumber);
            })
            //显示算力弹窗
            $(".showAllPower").click(function () {
                var param = {
                    dtype: "dialog220",
                    data: {
                        newAllPower: allPower + limitRentUnit,
                        powerList: [{
                            name: "基础算力",
                            Power: dataPower.basePower + limitRentUnit
                        },
                        {
                            name: "浮动算力",
                            Power: dataPower.floatPower + limitRentUnit
                        },
                        {
                            name: "达标算力",
                            Power: dataPower.pePower + limitRentUnit
                        },
                        {
                            name: "期货算力",
                            Power: dataPower.futuresPower + limitRentUnit
                        },
                        {
                            name: "定期算力",
                            Power: dataPower.standPower + limitRentUnit
                        }
                        ]
                    }
                };
                app.dialog(param);
            });
            //点击租用
            var acceptRent = true; //租用点击延时
            function Continue() {
                if (!acceptRent) {
                    app.toast('请勿重复提交');
                    return;
                }
                acceptRent = false;
                setTimeout(function () {
                    acceptRent = true;
                }, 1000);
                rentMachine();
            }
            $(".rementLabel").click(function () {
                if (agreementinput == false) {
                    agreementinput = true;
                    $(".ag_checkedstyle").removeClass('agreement_style').addClass('agreement_style_checked');
                    $(".rentBtn").removeClass('notAgree')
                } else {
                    agreementinput = false;
                    $(".ag_checkedstyle").removeClass('agreement_style_checked').addClass('agreement_style');
                    $(".rentBtn").addClass('notAgree')
                }
            });
            $(".showContract").on("click", ".rementLink", function () {
                var thisValue = $(this).attr("data-value");
                var title = thisValue.split("&")[0];
                var contentId = thisValue.split("&")[1];
                app.ajaxPro({
                    url: "machine/get-contact",
                    values: {
                        token: account.token,
                        code: contentId,
                        machine_id: machineId,
                        num: rent_num,
                        currency: payMethod
                    },
                    openFlower: true
                }, function (ret) {
                    if (ret.code == 200) {
                        var param = {
                            dtype: "dialog391",
                            data: {
                                title: ret.data.contact.name,
                                orderText: ret.data.contact.content,
                                btns: [{
                                    name: "我已阅读并同意",
                                    event: "okRentMachine"
                                }],
                                extra: {}
                            }
                        };
                        app.dialog(param);
                    } else {
                        app.toast(ret.message)
                    }
                })
            })
            function checkSubNum() {
                if (isInstallment == 1 && isAllPayment == 0 && $("#checkInput").prop("checked") == false) {
                    app.toast("该产品不支持全款购买");
                    return
                }
                if (showAddWindow() == true) {
                    if (not_return == 10) {
                        var param = {
                            dtype: "dialog53",
                            data: {
                                title: '提示',
                                text: '该合约到期后自动停挖，不可进行退单、转让、续单等操作，不产生算龄，是否继续支付？',
                                cancel: 'cancel',
                                confirm: 'confirm',
                                cancentxt: '取消',
                                confirmtxt: '继续',
                                stopPropagation: true,//阻止点击body冒泡
                            }
                        };
                        //提示公共弹窗
                        app.dialog(param);
                        app.listen('confirm', function () {
                            Continue();
                        });
                        return;
                    }
                    Continue();
                }
            }
            if (is_captcha == 1) {
                _fmOpt = {
                    display: 'bind', //popup方式渲染验证码
                    container: '#checkButton', //验证码button渲染的目标DOM，自动展现方式下必需，详情见后文
                    area: '.customForm', //对于custom模式，弹出窗口的加载容器，详情见后文
                    partner: "renrenkj",
                    appName: "renrenkj_h5",
                    width: "6.9rem",
                    height: "0.88rem",
                    fmb: true,
                    initialTime: new Date().getTime(),
                    token: "renrenkj" + "-" + new Date().getTime() + "-" + Math.random().toString(16).substr(2),
                    env: 1,
                    getinfo: function () {
                        return "e3Y6ICIyLjUuMCIsIG9zOiAid2ViIiwgczogMTk5LCBlOiAianMgbm90IGRvd25sb2FkIn0=";
                    },
                };
                var fm = document.createElement('script');
                fm.type = 'text/javascript';
                fm.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'static.tongdun.net/captcha/main/tdc.js?ver=1.0&t=' + (new Date().getTime() / 600000).toFixed(0);
                var s = document.getElementsByTagName('script')[0];
                s.parentNode.insertBefore(fm, s);
                _fmOpt.onSuccess = function (validateToken) {
                    if (validateToken) {
                        if (app.ST == "ios") {
                            app.onEvent("count", "buybtcmachine");
                        } else {
                            app.onEvent("count", "buybtcmachineanzhuo");
                        }
                        validateTokenNew = validateToken;
                        if (agreementinput == true) {
                            checkSubNum();
                        } else {
                            app.toast("请同意协议");
                        }
                    } else {
                        _fmOpt.reset();
                    }
                };
            } else {
                $("#checkButton").click(function () {
                    if (app.ST == "ios") {
                        app.onEvent("count", "buybtcmachine");
                    } else {
                        app.onEvent("count", "buybtcmachineanzhuo");
                    }
                    if (agreementinput == true) {
                        checkSubNum();
                    } else {
                        app.toast("请同意协议");
                    }
                })
            }
            app.listen("okRentMachine", function () {
                if (agreementinput == false) {
                    $(".rementLabel").click();
                }
            });
            app.listen("checkRealName", function () {
                var goCerfition = {
                    page: "common/headerwin",
                    name: "choosecerfertion_headerwin",
                    param: {
                        subpage: "my/choosecerfertiontwo",
                        name: "choosecerfertiontwo",
                        title: "实名校验",
                        goAddMoney: true
                    }
                };
                var recoinNumber = JSON.stringify(goCerfition);
                app.goPushPage(recoinNumber);
            });
            var events = [
                "bhpcCountChange",
                "littlemoney_recharge_success",
                "buycoin_success",
                "buyBcnySucceed"
            ];
            app.listen(events, function () {
                loadPage();
            });
            app.listen("viewDetails", function () {
                var cointypecontract = {
                    page: "common/headerwin",
                    name: "newmypower_headerwin",
                    param: {
                        subpage: "mine/newmypower",
                        name: "newmypower",
                        title: "我的合约"
                    }
                };
                var recoinNumber = JSON.stringify(cointypecontract);
                app.goPushPage(recoinNumber);
            })
            app.listen("rent_success", function () {
                app.closeW("machine_newrent");
            })
            app.headerMap();
        }
    </script>
    <script type="text/html" id="fenQiContant">
        {{~it:item:index}}
        <li data-mouthNum={{=item.period_number}} data-onceFee={{=item.once_fee}} data-onceRepayment={{=item.once_repayment}} data-skuId={{=item.sku_code}} data-moneyNum={{=item.total_repayment}} data-benjing={{=item.total_repaymentnew}} data-sevrieCharge={{=item.totalSevrce}}  class={{=index=='0'? "chooseli":"" }}>
            <p>
                {{=item.once_repayment}} CNY * {{=item.period_number}}期
            </p>
            <p>
                <span>
                    含服务费 {{=item.once_fee}} CNY/期
                </span>
            </p>
            <p class="showDischareNum"  style="display:{{=item.is_discount==true? 'block':'none'}};">
                {{=item.original_fee}} CNY/期
            </p>
        </li>
        {{~}}
    </script>
</body>

</html>